﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace EasyPiano
{
    public enum ShrinkOritation
    {
        Top,Bottom,Right,Left
    }
    public partial class ShrinkControl : ContainerControl
    {
        ShrinkOritation oritation;
        int size = 20;
        bool isShrinking = false;
        Button shrinkBt;

        public ShrinkControl()
        {
            InitializeComponent();
            shrinkBt = new Button();
            shrinkBt.Dock = System.Windows.Forms.DockStyle.Right;
            shrinkBt.Size = new Size(20, 20);           
            shrinkBt.TabIndex = 1;
            shrinkBt.Text = "-";
            shrinkBt.UseVisualStyleBackColor = true;
            shrinkBt.Click += new System.EventHandler(this.bt_Click);            
            this.Controls.Add(shrinkBt);

            this.Controls.SetChildIndex(shrinkBt, 0);
            this.DoubleBuffered = true;
            oritation = ShrinkOritation.Right;
        }

        public ShrinkOritation Oritation
        {   get => oritation;
            set
            {
                oritation = value;
                if (shrinkBt != null)
                {
                    switch (oritation)
                    {
                        case ShrinkOritation.Top:
                            shrinkBt.Dock = System.Windows.Forms.DockStyle.Top;
                            break;
                        case ShrinkOritation.Bottom:
                            shrinkBt.Dock = System.Windows.Forms.DockStyle.Bottom;
                            break;
                        case ShrinkOritation.Right:
                            shrinkBt.Dock = System.Windows.Forms.DockStyle.Right;
                            break;
                        case ShrinkOritation.Left:
                            shrinkBt.Dock = System.Windows.Forms.DockStyle.Left;
                            break;
                        default:
                            break;
                    }
                }
            }                
        }

        private void bt_Click(object sender, EventArgs e)
        {
            Button button = (Button)sender;
            isShrinking = !isShrinking;
            if (isShrinking)
            {
                button.Text = "+";
                if (oritation == ShrinkOritation.Left || oritation == ShrinkOritation.Right)
                {
                    size = this.Width;
                    this.Width = button.Width;
                }
                else
                {
                    size = this.Height;
                    this.Height = button.Height;
                }                
            }
            else
            {
                button.Text = "-";
                if (oritation == ShrinkOritation.Left || oritation == ShrinkOritation.Right)
                {
                    this.Width = size;
                }
                else
                {
                    this.Height = size;
                }                
            }
        }
    }
}
